/*
 * Purpose: Act as a Fascade for the Text file reading
 */

package Util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 *
 * @author jase
 */
public class FileSystem {

	private static final String NEWLINE = System.getProperty("line.separator");

	public static String readAll(String name) {
		StringBuffer  buf = new StringBuffer();

		try {

			BufferedReader reader = new BufferedReader(new java.io.FileReader(name));

			while (true) {
				String line = reader.readLine();
				if (line == null) break;
				if (line.length() < 1) continue;
				buf.append(line + NEWLINE); // NOTE: need to re-add newlines...
			}

			reader.close();

		} catch (Exception e) {
			return null;
		}

		return buf.toString();
	}


	public static void writeAll(String name, String text) {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(name));
			text.trim();
			writer.write(text, 0, text.length());
			writer.close();
		} catch (Exception e) {
		}
	}

}
